<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<c:choose>
	
	<c:when test="${articlePage.list.size() == 0 }">您还没有发表文章，请先发布一篇文章！</c:when>
	<c:otherwise>
		<c:forEach items="${articlePage.list }" var="article">
					<div class="card" style = "margin-top:10px;">
					  <div class="card-body">
					    <blockquote class="blockquote mb-0">
					    	<div class = "row">
					    		<div class = "col-md-3">
					    			<img alt="" src="/pic/${article.picture }" onerror="javascript:this.src='/resources/js/images/3.jpg'" width = "80px" height = "60px">
					    		</div>
					    		<div class = "col-md-9">
							    	<p>${article.title }</p>
							      	<p>${article.author.username }
							      		时间：<fmt:formatDate value="${article.created}" pattern="yyyy-MM-dd"/>
							      	</p>
							      	<p>状态：
							      		<c:if test="${article.status==0 }">通过</c:if>
							      		<c:if test="${article.status==1 }">未通过</c:if>
										
							      	</p>
							      	<button type="button" class="btn btn-primary" onclick = "updateOne(${article.id})">修改</button>
							      	<button type="button" class="btn btn-danger" onclick = "del(${article.id})">删除</button>
					    		</div>
					    	</div>	
					    </blockquote>
					  </div>
					</div>
				</c:forEach>
				
				<!--分页以后如何把页面渲染回原来的home.js页面  -->
				<!--分页  -->
					<nav aria-label="Page navigation example">
					  <ul class="pagination">
					    <li class="page-item">
					      <a class="page-link" href="/article/myArticles?pageNum=1" aria-label="Previous">
					        <span aria-hidden="true">&laquo;</span>
					      </a>
					    </li>
					    <c:forEach begin="${articlePage.pageNum-2>1?articlePage.pageNum-2:1 }"
					    	 end="${articlePage.pageNum+2<articlePage.pages?articlePage.pageNum+2:articlePage.pages }" step="1" var = "page">
					   	 	<li class="page-item"><a class="page-link" href="/article/myArticles?pageNum=${page }">${page }</a></li>
					   </c:forEach>
					    <li class="page-item">
					      <a class="page-link" href="/article/myArticles?pageNum=${articlePage.pages }" aria-label="Next">
					        <span aria-hidden="true">&raquo;</span>
					      </a>
					    </li>
					  </ul>
					</nav>				                                                                                                                  
				<!--分页  -->
	
	
	
	</c:otherwise>
</c:choose>


<script type="text/javascript"> 

	function del(id){
		
		if(confirm("确定删除么？")){
			
			$.post("/article/delOne" ,{id:id} ,function(msg){
				
				if(msg.id == 0){
					alert("删除成功");
					location = "/user/home";
				}else{
					alert("删除失败")
				}
			})	
			
		}
	
	}
	
	function updateOne(id){
		
		location = "/article/toUpdateOne?id="+id;
		
	}




</script>